package linwen.wang.controller;

import linwen.wang.commom.ReturnVO;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Length;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;

/**
 * @ClassName BUserController
 * @Description TODO
 * @Author zero
 * @DATE 2023/8/1 1:38 PM
 * @Version 1.0
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/b/user")
public class BUserController {

    // RequestMapping / PathVariable 参数校验。校验失败会抛出 ConstraintViolationException 异常。
    @GetMapping("/fun2/{userId}")
    public Object fun2(@PathVariable @Min(10000L) Long userId) {
        // 校验通过，才会执行业务逻辑处理
        return ReturnVO.buildReturnVO("success");
    }

    // RequestMapping / PathVariable 参数校验。校验失败会抛出 ConstraintViolationException 异常。
    @GetMapping("fun3")
    public Object fun3(@Length(min = 5, max = 10) @NotNull String username) {
        // 校验通过，才会执行业务逻辑处理
        return ReturnVO.buildReturnVO("success");
    }
}
